// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: yuanchenxi 836909158@qq.com
 * @Date: 2024-10-09 10:51:59
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2024-12-23 14:50:27
 * @FilePath: \SGFEM\Import\NastranBDF\src\Element\CONM1Parser.cpp
 */
#include "Import/BDFImport/BulkData/Element/CONM1Parser.h"

#include <iostream>

#include "boost/algorithm/string.hpp"

#include "Utility/Logging/SGLogger.h"

#include "DataStructure/Input/Element/CONM1Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFImport.h"
#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure;
BULKDATA_ENTRY_PARSER_REG (CONM1);

/*
// file://./../../Doc/MarkDown/BulkData/CONM1/CONM1.md>
*/
// 以下需要修改
enum CONM1key
{
    CONM1KEY_EID  = 2,
    CONM1KEY_NODE = 3,
    CONM1KEY_CID  = 4,
    CONM1KEY_M11  = 5,
    CONM1KEY_M21  = 6,
    CONM1KEY_M22  = 7,
    CONM1KEY_M31  = 8,
    CONM1KEY_M32  = 9,
    CONM1KEY_M33  = 12,
    CONM1KEY_M41  = 13,
    CONM1KEY_M42  = 14,
    CONM1KEY_M43  = 15,
    CONM1KEY_M44  = 16,
    CONM1KEY_M51  = 17,
    CONM1KEY_M52  = 18,
    CONM1KEY_M53  = 19,
    CONM1KEY_M54  = 22,
    CONM1KEY_M55  = 23,
    CONM1KEY_M61  = 24,
    CONM1KEY_M62  = 25,
    CONM1KEY_M63  = 26,
    CONM1KEY_M64  = 27,
    CONM1KEY_M65  = 28,
    CONM1KEY_M66  = 29,

};

SG::DataStructure::Common::Status BDF::BULKDATA::ParseCONM1 (const std::shared_ptr<SG::DBManager::DBServiceFactory>& dbServiceFactory,
                                                             std::vector<std::string>&                               dividedEntryInfo)
{
    SG::DataStructure::FEM::CONM1Data tempCONM1;

    int curIDKey = 1;  // 当前字符串是第几项

    for (auto curStrKey : dividedEntryInfo)
    {
        bool isEmpty = is_all_space (curStrKey);
        if (isEmpty)
        {
            curIDKey++;
            continue;
        }

        switch (curIDKey)
        {
        case CONM1KEY_EID:
            tempCONM1.m_id = std::stoull (curStrKey);
            break;
        case CONM1KEY_NODE:
            tempCONM1.m_g[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_CID:
            tempCONM1.m_cId = std::stoull (curStrKey);
            break;
        case CONM1KEY_M11:
            tempCONM1.m_m1[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M21:
            tempCONM1.m_m2[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M22:
            tempCONM1.m_m2[1] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M31:
            tempCONM1.m_m3[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M32:
            tempCONM1.m_m3[1] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M33:
            tempCONM1.m_m3[2] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M41:
            tempCONM1.m_m4[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M42:
            tempCONM1.m_m4[1] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M43:
            tempCONM1.m_m4[2] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M44:
            tempCONM1.m_m4[3] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M51:
            tempCONM1.m_m5[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M52:
            tempCONM1.m_m5[1] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M53:
            tempCONM1.m_m5[2] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M54:
            tempCONM1.m_m5[3] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M55:
            tempCONM1.m_m5[4] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M61:
            tempCONM1.m_m6[0] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M62:
            tempCONM1.m_m6[1] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M63:
            tempCONM1.m_m6[2] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M64:
            tempCONM1.m_m6[3] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M65:
            tempCONM1.m_m6[4] = std::stoull (curStrKey);
            break;
        case CONM1KEY_M66:
            tempCONM1.m_m6[5] = std::stoull (curStrKey);
            break;
        }
        curIDKey++;
    }

    return dbServiceFactory->get<IElementService> ()->Add (tempCONM1);
}
